package com.firefighting.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.firefighting.dao.EnclosureMapper;
import com.firefighting.entity.Contract;
import com.firefighting.entity.Enclosure;

@Service
public class EnclosureService {

	@Autowired
	private EnclosureMapper enclosureMapper;
	public void updateEnclosure(Enclosure enclosure) {
		// TODO Auto-generated method stub
		if(enclosureMapper.selectByBuildingId(enclosure.getBuildingId()).size() != 0){//更新
			enclosureMapper.updateByBuildingId(enclosure);
		}else{//添加
			enclosureMapper.insert(enclosure);
		}
	}
	/**
	 * @author Hanjd
	 * @function 删除建筑物
	 * 
	 * */
	@Transactional 
	public void deleteById(int id) {
		// TODO Auto-generated method stub
		try{
			enclosureMapper.deleteByPrimaryKey(id);
		}catch(Exception e){
			e.printStackTrace();  
            throw new RuntimeException("删除失败");  
		}
		
	}
	/*hanjd 查询建筑物的围栏信息*/
	public Enclosure queryContract(int id)
	{
		return enclosureMapper.selectByPrimaryKey(id);
	}
}
